#ifndef MODBUS_RTU_HPP
#define MODBUS_RTU_HPP

#include <vector>
#include <string>

class ModbusRTU {
public:
    explicit ModbusRTU(const std::string& port, int baud_rate = 9600, int slave_address = 0x33);
    ~ModbusRTU();

    bool connect();
    void disconnect();

    // 读取保持寄存器
    bool readHoldingRegisters(uint16_t start_register, uint16_t register_count,
                              std::vector<uint16_t>& out_values);

private:
    std::string port_;
    int baud_rate_;
    int slave_address_;
    int serial_fd_;

    uint16_t calculateCRC(const uint8_t* data, size_t length);
};

#endif // MODBUS_RTU_HPP